package com.springcloud.market.api.controller;

import com.springcloud.market.api.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/stock")
public class StockController {
    
    @Autowired
    private StockService stockService;
    
    @RequestMapping("/reduce")
    public String reduce() {
        System.out.println("扣减库存");
        return "扣减库存";
    }

    @RequestMapping("/readStock")
    public String readStock(){
        System.out.println("网关测试：stock服务");
        return "网关测试：stock服务";
    }
    
    @RequestMapping("/reduceStock")
    public String reduceStock(@RequestParam("productId") Long productId, @RequestParam("quantity") Integer quantity) {
        return stockService.reduceStock(productId, quantity);
    }

    @PostMapping("/seata/reduce")
    public String seataReduce(@RequestParam("productId")Integer productId){
        stockService.reduce(productId);
        System.out.println("扣减库存");
        return "扣减库存"+productId;
    }

}
